<template>

  <div style="background: darkgray">

    {{nameee}} <br>
    {{tnameee}}登录成功
    <div style="background: #44B6AE; width: 2032px;height:100px" >
      <h1 style="color: aliceblue;" >
        成裕生产管理系统
      </h1>


    </div>
    <div  class="tools_bar">
      <a title @click="sx" class="tools_btn">
        <span class   >
          <b style="background: url('')  50% 4px no-repeat;  ">
             刷新
          </b>
        </span>
      </a>
      <a title @click="pdf" class="tools_btn">
        <span class   >
          <b style="background: url('')  50% 4px no-repeat;  ">
             pdf生成
          </b>
        </span>
      </a>
      <a title @click="openadd" class="tools_btn">
        <span class   >
          <b style="background: url('https://mes.chengyuyun.top/Themes/images/16/application_add.png')  50% 4px no-repeat;  ">
             新增
          </b>
        </span>
      </a>
    </div>
    <el-form :inline="true" :model="stu" class="demo-form-inline">
      <el-form-item label="订单编号">
        <el-input v-model="stu.dname" placeholder="订单编号"></el-input>
      </el-form-item>
      <el-form-item label="客户名称">
        <el-input v-model="stu.kname" placeholder="客户名称"></el-input>
      </el-form-item>
      <el-form-item label="合同">
        <el-input v-model="stu.hname" placeholder="合同"></el-input>
      </el-form-item>
      <el-form-item label="时间1">
        <el-input type="date"  v-model="stu.anddate1" placeholder="时间1"></el-input>
      </el-form-item>
      <el-form-item label="时间2">
        <el-input type="date" v-model="stu.anddate2" placeholder="时间2"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="list" style="background: dimgrey">搜索</el-button>
      </el-form-item>



    </el-form>
    <template>
      <el-table
          :data="table"
          border
          style="width: 100%">
        <el-table-column
            prop="id"
            label="编号"
            width="180">
        </el-table-column>
        <el-table-column
            prop="dname"
            label="订单编号"
            width="180">
        </el-table-column>
        <el-table-column
            prop="kname"
            label="客户名称">
        </el-table-column>
        <el-table-column
            prop="hname"
            label="合同">
        </el-table-column>
        <el-table-column
            prop="price"
            label="价格">
        </el-table-column>
        <el-table-column
            prop="yprice"
            label="原价">
        </el-table-column>
        <el-table-column
            prop="anddate"
            label="起初时间">
        </el-table-column>
        <el-table-column
            prop="enddate"
            label="结束时间">
        </el-table-column>
        <el-table-column
            fixed="right"
            label="操作"
            width="100">
          <template slot-scope="scope">
            <el-button @click="xg(scope.row)" type="text" size="small">修改</el-button>
            <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
            <el-button @click="xq(scope.row)" type="text" size="small">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
    </template>
    <el-pagination
        @current-change="getpage"
        :page-size="stu.pageSize"
        :page-count="stu.pageNum"
        layout="total, prev, pager, next"
        :total="total">
    </el-pagination>
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="stt">
        <el-form-item label="订单号" :label-width="formLabelWidth">
          <el-input v-model="stt.dname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="客户名称" :label-width="formLabelWidth">
          <el-input v-model="stt.kname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="合同" :label-width="formLabelWidth">
          <el-input v-model="stt.hname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="价格" :label-width="formLabelWidth">
          <el-input v-model="stt.price" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="原价" :label-width="formLabelWidth">
          <el-input v-model="stt.yprice" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="开始时间" :label-width="formLabelWidth">
          <el-input type="date" v-model="stt.anddate" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="结束时间" :label-width="formLabelWidth">
          <el-input type="date" v-model="stt.enddate" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="add">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "DDView",
  data() {
    return {

      stt:{},
      dialogFormVisible:false,
      formLabelWidth:"100px",
      stu:{
        pageNum:1,
        pageSize:3,
      },
      table:[],
      total:0,
      nameee:sessionStorage.getItem("nameee"),
      tnameee:sessionStorage.getItem("tnameee"),
    }
  }, methods: {
    xq(id){
      this.axios.get("user/dd/xq?id="+id.id).then(res=>{
           sessionStorage.setItem("tname",res.data.data.tname);
        sessionStorage.setItem("dname",res.data.data.dname);
        sessionStorage.setItem("hname",res.data.data.hname);
        sessionStorage.setItem("enddate",res.data.data.enddate);
        sessionStorage.setItem("anddate",res.data.data.anddate);
        sessionStorage.setItem("price",res.data.data.price);
        sessionStorage.setItem("yprice",res.data.data.yprice);
        sessionStorage.setItem("id",res.data.data.id);
        this.$router.push('ddxq')
      })
    },
    pdf(){
      window.location='http://localhost:10010/user/dd/pdf';
    },
    sx(){
        this.$router.push('dd');
       this.list();
         this.$message.success("刷新成功")

    },
    del(id){
      this.axios.get("dd/del?id="+id.id).then(res=>{
        if(res.data.code==1){
          this.$message.success(res.data.msg);
          this.list();
        }else{
          this.$message.error(res.data.msg);
        }
      })
    },
    xg(row){
      this.dialogFormVisible=true;
      this.stt=row;
    },
    openadd(){
      this.dialogFormVisible=true;
    },
    add(){
      this.axios.get("dd/add",{params:this.stt}).then(res=>{
          if(res.data.code==1){
            this.$message.success(res.data.msg);
            this.dialogFormVisible=false;
            this.list();
          }else{
            this.$message.error(res.data.msg);
          }
      })
    },
    getpage(page){
      this.stu.pageNum=page;
      this.list();
    },
    list(){
      this.axios.get("dd/list",{params:this.stu}).then(res=>{
        this.total=res.data.total;
        this.table=res.data.list;
      })
    }

  }, created() {
    this.list();
  }
}
</script>

<style scoped>
.tools_btn{
  cursor: pointer;
  float: left;
  display: block;
  margin: 3px 3px 0;
  padding: 0 0 0 10px;
  height: 39px;
  overflow: hidden;
}
.tools_bar{
  padding-left: 5px;
  height: 45px;
  border: #ccc 1px solid;
  background: #F7F7F7;
}
.tools_btn span b{
  font-weight: normal;
  display: block;
  padding: 22px 0 5px;
  line-height: 15px
}
</style>